package com.woniu.zsd.platform.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniu.zsd.common.util.Result;
import com.woniu.zsd.platform.annotation.RequirePermission;
import com.woniu.zsd.platform.annotation.RequireRole;
import com.woniu.zsd.platform.form.AddSuggestionForm;
import com.woniu.zsd.platform.form.ReplySuggestionForm;
import com.woniu.zsd.platform.param.AddSuggestionParam;
import com.woniu.zsd.platform.param.ReplySuggestionParam;
import com.woniu.zsd.platform.service.SuggestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangtao
 * @since 2025年02月18日
 */
@RestController
@RequestMapping("/suggestion")
@Api(tags = "建议管理类接口")
public class SuggestionController {
    @Resource
    private SuggestionService suggestionService;

    //新增留言建议
    @PostMapping("/addSuggestion")
    @ApiOperation("新增留言建议")
    public Result addSuggestion(@RequestBody AddSuggestionForm form) throws Exception {
        suggestionService.addSuggestion(BeanUtil.toBean(form, AddSuggestionParam.class));
        return Result.success("新增建议成功");
    }

    //回复留言
    @PostMapping("/replySuggestion")
    @ApiOperation("回复建议")
    @RequireRole({"超级管理员"})
    @RequirePermission("回复留言")
    public Result replySuggestion(@RequestBody ReplySuggestionForm form) throws Exception {
        suggestionService.replySuggestion(BeanUtil.toBean(form, ReplySuggestionParam.class));
        return Result.success("回复建议成功");
    }

}

